package cc.lj.internal.coupons.infrastructure.repository.mysql;

import cc.lj.internal.core.exception.ServiceException;
import cc.lj.internal.core.model.BasePageHelper;
import cc.lj.internal.core.model.BasePageHelper2;
import cc.lj.internal.coupons.domain.martcap.model.vo.MultipleModelDO;
import cc.lj.internal.coupons.domain.martcap.repository.IMultipleModelRepository;
import cc.lj.internal.coupons.infrastructure.dao.IMultipleModelMapper;
import cc.lj.internal.coupons.infrastructure.excepion.CoupousExceptionEnum;
import cc.lj.internal.coupons.infrastructure.po.MultipleModelPO;
import cc.lj.internal.coupons.interfaces.dto.query.MultipleModelListQuery;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository("mysqlMultipleModelRepository")
public class MysqlMultipleModelRepositoryImpl implements IMultipleModelRepository,BasePageHelper<MultipleModelPO> {

    @Autowired
    private IMultipleModelMapper multipleModelMapper;

    @Override
    public Integer insert(MultipleModelPO multipleModelPO) {
        Integer row = multipleModelMapper.insert(multipleModelPO);
        if(row!=1)
        {
            throw new ServiceException(CoupousExceptionEnum.MULTIPLE_MODEL_INSERT_ERROR);
        }
        return multipleModelPO.getId();
    }

    @Override
    public MultipleModelPO getById(Integer id) {
        MultipleModelPO multipleModelPO = multipleModelMapper.selectById(id);
        if(multipleModelPO==null) {
            throw new ServiceException(CoupousExceptionEnum.GETONE_MODEL_NULL);
        }
        return multipleModelPO;
    }

    @Override
    public Integer updateById(MultipleModelPO multipleModelPO) {
        Integer row = multipleModelMapper.updateById(multipleModelPO);
        if(row!=1)
        {
            throw new ServiceException(CoupousExceptionEnum.MULTIPLE_MODEL_UPDATE_ERROR);
        }
        return row;
    }

    /**
     * 获取列表，无分页
     * @param
     * @return
     */
    @Override
    public List<MultipleModelPO> getList(MultipleModelPO multipleModelPO) {
        return this.list(multipleModelPO);
    }

    /**
     * BasePageHelper2的函数
     * @param param 查询参数
     * @return
     */
    @Override
    public List<MultipleModelPO> list(MultipleModelPO param) {
        QueryWrapper<MultipleModelPO> wrapper = new QueryWrapper(param);
        List<MultipleModelPO> list = multipleModelMapper.selectList(wrapper);
        return list;
    }
}
